from sqlalchemy.ext.asyncio import AsyncSession as Session
from app.models.waveup.wp_wallet import WpWallet
from sqlalchemy import select
from typing import List

async def qry_wp_wallet_list(
    session: Session,
    uid: int,
    page_no: int = 1,
    page_size: int = 100,
    product_ids: List[str] = [],
) -> List[WpWallet]:
    """查询WaveUp钱包列表"""
    statement = select(WpWallet).where(WpWallet.uid == uid)
    if len(product_ids) > 0:
        statement = statement.where(WpWallet.productId.in_(product_ids))
    # 计算总数
    total = await session.execute(statement)
    total = len(total.scalars().all())
    # 分页查询
    statement = statement.offset((page_no - 1) * page_size).limit(page_size)
    result = await session.execute(statement)

    return {
        "records": result.scalars().all(),
        "total": total,
        "pageNo": page_no,
        "pageSize": page_size
    }